﻿using System.Net;
using System.Net.Http;
using Exceptionless.Json;
using Microsoft.AspNetCore.Mvc;
using ZilLion.Service.Core.Domain.EntityBase;
using JsonConvert = Newtonsoft.Json.JsonConvert;

namespace ZilLion.Service.Core.Starter.Controllers
{
    /// <summary>
    ///     Represents controller that exposes routes for error viewing.
    /// </summary>
   
    public class ErrorController : Controller
    {
        /// <summary>
        ///     Intercepts rout not found error in order to show it as friendly message on the screen.
        /// </summary>
        /// <param name="path">Path.</param>
        /// <returns>404 with <see cref="ErrorInfoModel" /> object as content.</returns>
        [HttpGet]
        [HttpPost]
        [HttpPut]
        [HttpPatch]
        [HttpDelete]
        [HttpHead]
        [HttpOptions]
        public JsonResult NotFound(string path)
        {
            var metadata = new ResponseBase
            {
                Errormodel = new WebErrorModel
                {

                    ErrMessage = $"[{Request.Path}] 未找到匹配路由",
                    Errtype = "404"
                }
            };
            return new JsonResult(metadata) { StatusCode = (int?)HttpStatusCode.NotFound };
        }
    }
}